/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package fplaton.ui;

import fplaton.db.SQLiteJDBC;
import fplaton.economics.EconomicsDao;
import fplaton.economics.EconomicsSectionController;
import static fplaton.economics.calculations.calculateTelikaDidaktra;
import fplaton.economics.databaseEconomicsSectionController;
import fplaton.helper.Validation.*;
import static fplaton.helper.Validation.isNullorEmpty;
import fplaton.economics.economicalStandards;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author chaliasos
 */
public class oikonomiko extends javax.swing.JFrame {

    /**
     * Creates new form oikonomiko
     */
    public oikonomiko() {
        initComponents();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        leftPanel = new javax.swing.JPanel();
        calculateButton = new javax.swing.JButton();
        regLabel = new javax.swing.JLabel();
        dayComboBox = new javax.swing.JComboBox();
        monthComboBox = new javax.swing.JComboBox();
        yearComboBox = new javax.swing.JComboBox();
        question1Label = new javax.swing.JLabel();
        question1ComboBox = new javax.swing.JComboBox();
        numberOfRelativesComboBox = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        gradeComboBox = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        numberOfCoursesComboBox = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        paymentComboBox = new javax.swing.JComboBox();
        autoDidaktraField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        rightPanel = new javax.swing.JPanel();
        arxikiMeiwsiLabel = new javax.swing.JLabel();
        gumn1Label = new javax.swing.JLabel();
        gumn2Label = new javax.swing.JLabel();
        gumn3Label = new javax.swing.JLabel();
        luk1Label = new javax.swing.JLabel();
        luk2Label = new javax.swing.JLabel();
        luk3Label = new javax.swing.JLabel();
        starterCutField = new javax.swing.JTextField();
        firstGradeField = new javax.swing.JTextField();
        secondGradeField = new javax.swing.JTextField();
        thirdGradeField = new javax.swing.JTextField();
        fourthGradeField = new javax.swing.JTextField();
        fifthGradeField = new javax.swing.JTextField();
        sixthGradeField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        meiwsiAnaPaidiLabel = new javax.swing.JLabel();
        cutPerKidField = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        saveButton = new javax.swing.JButton();
        settingsPanel = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        clearButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Οικονομικός τομέας");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setMinimumSize(new java.awt.Dimension(1079, 800));
        setName("ecoFrame"); // NOI18N

        leftPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.darkGray));
        leftPanel.setMaximumSize(new java.awt.Dimension(1920, 1080));
        leftPanel.setMinimumSize(new java.awt.Dimension(800, 600));
        leftPanel.setPreferredSize(new java.awt.Dimension(800, 600));

        calculateButton.setText("Υπολόγισε");
        calculateButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                calculateButtonMouseClicked(evt);
            }
        });

        regLabel.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        regLabel.setText("Εγγραφή");

        dayComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Ημέρα", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        dayComboBox.setToolTipText("Εδώ δηλώνεται η ημέρα εγγραφής του μαθητή.");

        monthComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Μήνας", "Ιανουάριος", "Φεβρουάριος", "Μάρτιος", "Απρίλιος", "Μάιος", "Ιούνιος", "Ιούλιος", "Αύγουστος", "Σεπτέμβριος", "Οκτώβριος", "Νοέμβριος", "Δεκέμβριος" }));
        monthComboBox.setToolTipText("Εδώ δηλώνεται ο μήνας εγγραφής του μαθητή.");

        yearComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Έτος", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2020" }));
        yearComboBox.setToolTipText("Εδώ δηλώνεται το έτος εγγραφής του μαθητή.");

        question1Label.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        question1Label.setText("Υπάρχουν μαθητές πρώτης συγγένειας που φοιτούν στο ίδιο φροντιστήριο;");

        question1ComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ΝΑΙ", "ΟΧΙ" }));
        question1ComboBox.setSelectedItem("ΟΧΙ");
        question1ComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                question1ComboBoxItemStateChanged(evt);
            }
        });

        numberOfRelativesComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5" }));
        numberOfRelativesComboBox.setVisible(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        jLabel3.setText("Fplaton Οικονομικός Τομέας");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(118, 118, 118)
                .addComponent(jLabel3)
                .addContainerGap(146, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jLabel3)
                .addContainerGap(29, Short.MAX_VALUE))
        );

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel4.setText("Σε ποια τάξη φοιτά ο μαθητής;");

        gradeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Επιλογή", "1η γυμνασίου", "2α γυμνασίου", "3η γυμνασίου", "-----------------", "1η λυκείου", "2α λυκείου", "3η λυκείου" }));

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel5.setText("Πόσα μαθήματα θα παρακολουθήσει;");

        numberOfCoursesComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Επιλογή", "1", "2", "3", "4", "5", "6", "7" }));

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel6.setText("Πως θα πληρωθεί το ποσό;");

        paymentComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Επιλογή", "Εφάπαξ", "1 δόση", "2 δόσεις", "3 δόσεις" }));

        autoDidaktraField.setEditable(false);
        autoDidaktraField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel7.setText("ανά παιδί");

        javax.swing.GroupLayout leftPanelLayout = new javax.swing.GroupLayout(leftPanel);
        leftPanel.setLayout(leftPanelLayout);
        leftPanelLayout.setHorizontalGroup(
            leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, leftPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(leftPanelLayout.createSequentialGroup()
                .addGap(55, 55, 55)
                .addGroup(leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(leftPanelLayout.createSequentialGroup()
                        .addComponent(calculateButton)
                        .addGap(75, 75, 75)
                        .addComponent(autoDidaktraField, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7))
                    .addGroup(leftPanelLayout.createSequentialGroup()
                        .addGroup(leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(question1Label)
                            .addGroup(leftPanelLayout.createSequentialGroup()
                                .addGroup(leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(gradeComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(numberOfCoursesComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(paymentComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addGap(35, 35, 35)
                        .addComponent(question1ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(numberOfRelativesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(leftPanelLayout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addComponent(regLabel)
                        .addGap(18, 18, 18)
                        .addComponent(dayComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(monthComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(yearComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(138, Short.MAX_VALUE))
        );
        leftPanelLayout.setVerticalGroup(
            leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(leftPanelLayout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(52, 52, 52)
                .addGroup(leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(regLabel)
                    .addComponent(dayComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(monthComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(yearComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(37, 37, 37)
                .addGroup(leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(gradeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(50, 50, 50)
                .addGroup(leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(numberOfCoursesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(48, 48, 48)
                .addGroup(leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(paymentComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 193, Short.MAX_VALUE)
                .addGroup(leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(question1Label)
                    .addComponent(question1ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(numberOfRelativesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(70, 70, 70)
                .addGroup(leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(calculateButton)
                    .addComponent(autoDidaktraField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addGap(113, 113, 113))
        );

        rightPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        SQLiteJDBC connection = new SQLiteJDBC("frontistirio.db");
        try {
            ResultSet rs = connection.executeQuery("SELECT * FROM ECONOMICS");
            economicalStandards ecoParse = new economicalStandards();
            while (rs.next()) {
                int arxMeiw = rs.getInt("ARXIKIMEIWSI");
                starterCutField.setText(String.valueOf(arxMeiw));
                ecoParse.setMeiwsi(arxMeiw);
                int meiwAnaPaidi = rs.getInt("MEIWSIANAPAIDI");
                cutPerKidField.setText(String.valueOf(meiwAnaPaidi));
                ecoParse.setMeiwsiAnaPaidi(meiwAnaPaidi);
                float costGumn1Math = rs.getFloat("KOSTOSGUMN1MATH");
                firstGradeField.setText(String.valueOf(costGumn1Math));
                ecoParse.setKostosGumn1AnaMathima(costGumn1Math);
                float costGumn2Math = rs.getFloat("KOSTOSGUMN2MATH");
                secondGradeField.setText(String.valueOf(costGumn2Math));
                ecoParse.setKostosGumn2AnaMathima(costGumn2Math);
                float costGumn3Math = rs.getFloat("KOSTOSGUMN3MATH");
                thirdGradeField.setText(String.valueOf(costGumn3Math));
                ecoParse.setKostosGumn3AnaMathima(costGumn3Math);
                float costLuk1Math = rs.getFloat("KOSTOSLUK1MATH");
                fourthGradeField.setText(String.valueOf(costLuk1Math));
                ecoParse.setKostosLuk1AnaMathima(costLuk1Math);
                float costLuk2Math = rs.getFloat("KOSTOSLUK2MATH");
                fifthGradeField.setText(String.valueOf(costLuk2Math));
                ecoParse.setKostosLuk2AnaMathima(costLuk2Math);
                float costLuk3Math = rs.getFloat("KOSTOSLUK3MATH");
                sixthGradeField.setText(String.valueOf(costLuk3Math));
                ecoParse.setKostosLuk3AnaMathima(costLuk3Math);
            }
        } catch (SQLException ex) {
            Logger.getLogger(oikonomiko.class.getName()).log(Level.SEVERE, null, ex);
        }

        arxikiMeiwsiLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        arxikiMeiwsiLabel.setText("Αρχική Μείωση");
        arxikiMeiwsiLabel.setFocusable(false);

        gumn1Label.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        gumn1Label.setText("1η Γυμνασίου");
        gumn1Label.setFocusable(false);

        gumn2Label.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        gumn2Label.setText("2α Γυμνασίου");
        gumn2Label.setFocusable(false);

        gumn3Label.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        gumn3Label.setText("3η Γυμνασίου");
        gumn3Label.setFocusable(false);

        luk1Label.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        luk1Label.setText("1η Λυκείου");
        luk1Label.setFocusable(false);

        luk2Label.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        luk2Label.setText("3η Λυκείου");
        luk2Label.setFocusable(false);

        luk3Label.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        luk3Label.setText("2α Λυκείου");
        luk3Label.setFocusable(false);

        starterCutField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        firstGradeField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        firstGradeField.setToolTipText("Εδώ δηλώνεται το κόστος ανά μάθημα για την συγκεκριμένα τάξη.");

        secondGradeField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        secondGradeField.setToolTipText("Εδώ δηλώνεται το κόστος ανά μάθημα για την συγκεκριμένα τάξη.");

        thirdGradeField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        thirdGradeField.setToolTipText("Εδώ δηλώνεται το κόστος ανά μάθημα για την συγκεκριμένα τάξη.");

        fourthGradeField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        fourthGradeField.setToolTipText("Εδώ δηλώνεται το κόστος ανά μάθημα για την συγκεκριμένα τάξη.");

        fifthGradeField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        fifthGradeField.setToolTipText("Εδώ δηλώνεται το κόστος ανά μάθημα για την συγκεκριμένα τάξη.");

        sixthGradeField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        sixthGradeField.setToolTipText("Εδώ δηλώνεται το κόστος ανά μάθημα για την συγκεκριμένα τάξη.");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("ΜΕΙΩΣΕΙΣ");
        jLabel1.setFocusable(false);

        meiwsiAnaPaidiLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        meiwsiAnaPaidiLabel.setText("Μείωση/παιδί");
        meiwsiAnaPaidiLabel.setFocusable(false);

        cutPerKidField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel8.setText("Κόστος Μαθημάτων");
        jLabel8.setFocusable(false);

        saveButton.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        saveButton.setText("Αποθήκευση");
        saveButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                saveButtonMouseClicked(evt);
            }
        });

        settingsPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel2.setText("Ρυθμίσεις");

        javax.swing.GroupLayout settingsPanelLayout = new javax.swing.GroupLayout(settingsPanel);
        settingsPanel.setLayout(settingsPanelLayout);
        settingsPanelLayout.setHorizontalGroup(
            settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(settingsPanelLayout.createSequentialGroup()
                .addGap(76, 76, 76)
                .addComponent(jLabel2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        settingsPanelLayout.setVerticalGroup(
            settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(settingsPanelLayout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addComponent(jLabel2)
                .addContainerGap(39, Short.MAX_VALUE))
        );

        clearButton.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        clearButton.setText("Καθαρισμός");
        clearButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                clearButtonMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout rightPanelLayout = new javax.swing.GroupLayout(rightPanel);
        rightPanel.setLayout(rightPanelLayout);
        rightPanelLayout.setHorizontalGroup(
            rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rightPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(rightPanelLayout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(jLabel8)
                        .addContainerGap(32, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, rightPanelLayout.createSequentialGroup()
                        .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(rightPanelLayout.createSequentialGroup()
                                .addComponent(arxikiMeiwsiLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(starterCutField, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(rightPanelLayout.createSequentialGroup()
                                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(luk1Label)
                                    .addComponent(gumn3Label)
                                    .addComponent(gumn2Label)
                                    .addComponent(gumn1Label)
                                    .addComponent(luk2Label)
                                    .addComponent(luk3Label))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(fifthGradeField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)
                                    .addComponent(fourthGradeField, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(thirdGradeField, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(firstGradeField, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(secondGradeField, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(sixthGradeField)
                                    .addComponent(cutPerKidField, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(29, 29, 29))))
            .addGroup(rightPanelLayout.createSequentialGroup()
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(settingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(rightPanelLayout.createSequentialGroup()
                        .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(rightPanelLayout.createSequentialGroup()
                                .addGap(87, 87, 87)
                                .addComponent(jLabel1))
                            .addGroup(rightPanelLayout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(meiwsiAnaPaidiLabel)))
                        .addGap(0, 66, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, rightPanelLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(saveButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(clearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(64, 64, 64))
        );
        rightPanelLayout.setVerticalGroup(
            rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rightPanelLayout.createSequentialGroup()
                .addComponent(settingsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(arxikiMeiwsiLabel)
                    .addComponent(starterCutField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(meiwsiAnaPaidiLabel)
                    .addComponent(cutPerKidField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(48, 48, 48)
                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(gumn1Label)
                    .addComponent(firstGradeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(gumn2Label)
                    .addComponent(secondGradeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(gumn3Label)
                    .addComponent(thirdGradeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(luk1Label)
                    .addComponent(fourthGradeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(luk3Label)
                    .addComponent(fifthGradeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(13, 13, 13)
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(luk2Label)
                    .addComponent(sixthGradeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(34, 34, 34)
                .addComponent(saveButton)
                .addGap(18, 18, 18)
                .addComponent(clearButton)
                .addContainerGap(187, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(leftPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rightPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(leftPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 800, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(rightPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void calculateButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_calculateButtonMouseClicked
        EconomicsSectionController ecoSectionController = new EconomicsSectionController();
        int relatives = 0;

        //Elegxos an sumplirothikan ola ta pedia.
        boolean verify = true;

        if (gradeComboBox.getSelectedItem().equals("Επιλογή") || gradeComboBox.getSelectedItem().equals("-----------------")) {
            verify = false;
            JOptionPane.showMessageDialog(null, "Error: Επιλέξτε την τάξη που φοιτά ο μαθητής.");
        }
        if (numberOfCoursesComboBox.getSelectedItem().equals("Επιλογή")) {
            verify = false;
            JOptionPane.showMessageDialog(null, "Error: Επιλέξτε το πλήθος των μαθημάτων που θα παρακολουθήσει ο φοιτητής");
        }
        if (paymentComboBox.getSelectedItem().equals("Επιλογή")) {
            verify = false;
            JOptionPane.showMessageDialog(null, "Error: Επιλέξτε τον τρόπο πληρωμής του ποσού.");
        }

        if (verify == true) {
            //Get number of relatives if exists
            if (question1ComboBox.getSelectedItem().equals("ΝΑΙ")) {
                String temp = (String) numberOfRelativesComboBox.getSelectedItem();
                relatives = Integer.parseInt(temp);
            }
            
            //Get number of Courses
            int numberOfCourses = Integer.parseInt((String) numberOfCoursesComboBox.getSelectedItem());

            //Get month of registration
            int months = ecoSectionController.getRegistrationMonth((String) monthComboBox.getSelectedItem(),
                    Integer.parseInt((String) dayComboBox.getSelectedItem()));

            if (months > 0) {

                //Prosdiorismos taxis foitisis kai upologismos didaktrwn.
                switch ((String) gradeComboBox.getSelectedItem()) {
                    case "1η γυμνασίου": {
                        float telikaDidaktra = calculateTelikaDidaktra(
                                Float.parseFloat(firstGradeField.getText()), numberOfCourses, months,
                                Integer.parseInt(starterCutField.getText()), Integer.parseInt(cutPerKidField.getText()),
                                (String) paymentComboBox.getSelectedItem(), relatives);
                        autoDidaktraField.setText(String.valueOf(telikaDidaktra));
                        break;
                    }
                    case "2α γυμνασίου": {
                        float telikaDidaktra = calculateTelikaDidaktra(
                                Float.parseFloat(secondGradeField.getText()), numberOfCourses, months,
                                Integer.parseInt(starterCutField.getText()), Integer.parseInt(cutPerKidField.getText()),
                                (String) paymentComboBox.getSelectedItem(), relatives);
                        autoDidaktraField.setText(String.valueOf(telikaDidaktra));
                        break;
                    }
                    case "3η γυμνασίου": {
                        float telikaDidaktra = calculateTelikaDidaktra(
                                Float.parseFloat(thirdGradeField.getText()), numberOfCourses, months,
                                Integer.parseInt(starterCutField.getText()), Integer.parseInt(cutPerKidField.getText()),
                                (String) paymentComboBox.getSelectedItem(), relatives);
                        autoDidaktraField.setText(String.valueOf(telikaDidaktra));

                        break;

                    }
                    case "1η λυκείου": {
                        float telikaDidaktra = calculateTelikaDidaktra(
                                Float.parseFloat(fourthGradeField.getText()), numberOfCourses, months,
                                Integer.parseInt(starterCutField.getText()), Integer.parseInt(cutPerKidField.getText()),
                                (String) paymentComboBox.getSelectedItem(), relatives);
                        autoDidaktraField.setText(String.valueOf(telikaDidaktra));

                        break;

                    }
                    case "2α λυκείου": {
                        float telikaDidaktra = calculateTelikaDidaktra(
                                Float.parseFloat(fifthGradeField.getText()), numberOfCourses, months,
                                Integer.parseInt(starterCutField.getText()), Integer.parseInt(cutPerKidField.getText()),
                                (String) paymentComboBox.getSelectedItem(), relatives);
                        autoDidaktraField.setText(String.valueOf(telikaDidaktra));
                        break;

                    }
                    case "3η λυκείου": {
                        float telikaDidaktra = calculateTelikaDidaktra(
                                Float.parseFloat(sixthGradeField.getText()), numberOfCourses, months,
                                Integer.parseInt(starterCutField.getText()), Integer.parseInt(cutPerKidField.getText()),
                                (String) paymentComboBox.getSelectedItem(), relatives);
                        autoDidaktraField.setText(String.valueOf(telikaDidaktra));
                        break;

                    }
                }
            }
        }

    }//GEN-LAST:event_calculateButtonMouseClicked

    private void question1ComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_question1ComboBoxItemStateChanged

        //Appear of numberOfRelativesComboBox
        String epilogiSuggenwn = (String) question1ComboBox.getSelectedItem();

        switch (epilogiSuggenwn) {
            case "ΟΧΙ":
                numberOfRelativesComboBox.setVisible(false);
                break;
            case "ΝΑΙ":
                numberOfRelativesComboBox.setVisible(true);
                break;
            default:
                numberOfRelativesComboBox.setVisible(false);
                break;
        }
    }//GEN-LAST:event_question1ComboBoxItemStateChanged

    private void saveButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveButtonMouseClicked

        int starterCut = 0, cutPerKid = 0;
        float firstGradeCost = 0, secondGradeCost = 0, thirdGradeCost = 0,
                fourthGradeCost = 0, fifthGradeCost = 0, sixthGradeCost = 0;

        boolean check = true;

        ArrayList<String> error = new ArrayList<>();

        //Checking if empty fields exist
        if (!isNullorEmpty(starterCutField.getText())) {
            starterCut = Integer.parseInt(starterCutField.getText());
        } else {
            check = false;
            error.add("Εισάγετε τιμή (%) ως αρχική μείωση.");
        }

        if (!isNullorEmpty(cutPerKidField.getText())) {
            cutPerKid = Integer.parseInt(cutPerKidField.getText());
        } else {
            check = false;
            error.add("Εισάγετε τιμή (%) ως μείωση ανά δεύτερο και έπειτα παιδί.");
        }

        if (!isNullorEmpty(firstGradeField.getText())) {
            firstGradeCost = Float.parseFloat(firstGradeField.getText());
        } else {
            check = false;
            error.add("Εισάγετε ετήσιο κόστος ανά μάθημα στην 1η Γυμνασίου.");
        }

        if (!isNullorEmpty(secondGradeField.getText())) {
            secondGradeCost = Float.parseFloat(secondGradeField.getText());
        } else {
            check = false;
            error.add("Εισάγετε ετήσιο κόστος ανά μάθημα στην 2α Γυμνασίου.");
        }

        if (!isNullorEmpty(thirdGradeField.getText())) {
            thirdGradeCost = Float.parseFloat(thirdGradeField.getText());
        } else {
            check = false;
            error.add("Εισάγετε ετήσιο κόστος ανά μάθημα στην 3η Γυμνασίου.");
        }

        if (!isNullorEmpty(fourthGradeField.getText())) {
            fourthGradeCost = Float.parseFloat(fourthGradeField.getText());
        } else {
            check = false;
            error.add("Εισάγετε ετήσιο κόστος ανά μάθημα στην 1η Λυκείου.");
        }

        if (!isNullorEmpty(fifthGradeField.getText())) {
            fifthGradeCost = Float.parseFloat(fifthGradeField.getText());
        } else {
            check = false;
            error.add("Εισάγετε ετήσιο κόστος ανά μάθημα στην 2α Λυκείου.");
        }

        if (!isNullorEmpty(sixthGradeField.getText())) {
            sixthGradeCost = Float.parseFloat(sixthGradeField.getText());
        } else {
            check = false;
            error.add("Εισάγετε ετήσιο κόστος ανά μάθημα στην 3η Λυκείου.");
        }

        //Save Economics Data to Database
        if (check == true) {
            databaseEconomicsSectionController controller = new databaseEconomicsSectionController(new EconomicsDao());
            controller.updateEconomics(starterCut, cutPerKid, firstGradeCost,
                    secondGradeCost, thirdGradeCost, fourthGradeCost, fifthGradeCost,
                    sixthGradeCost, this);
        } else {
            JOptionPane.showMessageDialog(null, error);
        }

    }//GEN-LAST:event_saveButtonMouseClicked

    private void clearButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clearButtonMouseClicked

        //Clear of settings section
        starterCutField.setText("");
        cutPerKidField.setText("");
        firstGradeField.setText("");
        secondGradeField.setText("");
        thirdGradeField.setText("");
        fourthGradeField.setText("");
        fifthGradeField.setText("");
        sixthGradeField.setText("");

    }//GEN-LAST:event_clearButtonMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel arxikiMeiwsiLabel;
    private javax.swing.JTextField autoDidaktraField;
    private javax.swing.JButton calculateButton;
    private javax.swing.JButton clearButton;
    private javax.swing.JTextField cutPerKidField;
    private javax.swing.JComboBox dayComboBox;
    private javax.swing.JTextField fifthGradeField;
    private javax.swing.JTextField firstGradeField;
    private javax.swing.JTextField fourthGradeField;
    private javax.swing.JComboBox gradeComboBox;
    private javax.swing.JLabel gumn1Label;
    private javax.swing.JLabel gumn2Label;
    private javax.swing.JLabel gumn3Label;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel leftPanel;
    private javax.swing.JLabel luk1Label;
    private javax.swing.JLabel luk2Label;
    private javax.swing.JLabel luk3Label;
    private javax.swing.JLabel meiwsiAnaPaidiLabel;
    private javax.swing.JComboBox monthComboBox;
    private javax.swing.JComboBox numberOfCoursesComboBox;
    private javax.swing.JComboBox numberOfRelativesComboBox;
    private javax.swing.JComboBox paymentComboBox;
    private javax.swing.JComboBox question1ComboBox;
    private javax.swing.JLabel question1Label;
    private javax.swing.JLabel regLabel;
    private javax.swing.JPanel rightPanel;
    private javax.swing.JButton saveButton;
    private javax.swing.JTextField secondGradeField;
    private javax.swing.JPanel settingsPanel;
    private javax.swing.JTextField sixthGradeField;
    private javax.swing.JTextField starterCutField;
    private javax.swing.JTextField thirdGradeField;
    private javax.swing.JComboBox yearComboBox;
    // End of variables declaration//GEN-END:variables
}
